<script setup lang="ts">
import { selectKvOptions, selectCharacterOptions } from '@/assets/setting.ts'
import { selectWallpaperValue } from '@/assets/global.ts'

function onClickCharacter($e: MouseEvent, index: number) {
  selectWallpaperValue.value = index
  const ele: HTMLElement = <HTMLElement>$e.target
  // 显示切换成功的反馈
  ele.classList.add('copied')
  setTimeout(() => {
    ele.classList.remove('copied')
  }, 1000)
}

function onClickKv($e: MouseEvent, index: number) {
  selectWallpaperValue.value = index
}
</script>

<template>
  <div class="wallpaper-setting">
    <a-typography-title :level="5">▌ 使用版本展示图</a-typography-title>
    <div class="kv-container">
      <div
        v-for="item in selectKvOptions"
        :key="item.value"
        class="kv-card"
        :class="item.value === selectWallpaperValue ? 'active' : ''"
        @click="$e => onClickKv($e, item.value)"
      >
        <div class="kv-pointer bounce-move"></div>
        <div class="avatar-img" style="background-image: none;">
          <img
            :alt="item.text"
            loading="lazy"
            :src="item.src"
          >
          <div class="copy-notification">已切换!</div>
        </div>
        <div class="avatar-name">{{ item.text }}</div>
      </div>
    </div>
    <a-typography-title :level="5">▌ 使用角色立绘</a-typography-title>
    <div class="character-container">
      <div
        v-for="item in selectCharacterOptions"
        :key="item.value"
        class="avatar-card rarity-5"
        :class="item.value === selectWallpaperValue ? 'outline active' : ''"
        @click="$e => onClickCharacter($e, item.value)"
      >
        <div class="halo"></div>
        <div class="avatar-img" style="background-image: none;">
          <img
            :alt="item.text"
            loading="lazy"
            :src="item.src"
          >
          <div class="copy-notification">已切换!</div>
        </div>
        <div class="avatar-name">{{ item.text }}</div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.wallpaper-setting {
  font-weight: bold;
}

.character-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
  max-width: 1200px;
  margin: 0 auto;
}

.avatar-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.2s;
}

.avatar-card:hover {
  transform: translateY(-5px);
}

.avatar-img {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  overflow: hidden;
  background-color: var(--card-bg);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  position: relative;

  .halo {
    visibility: hidden;
  }
}

.avatar-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-name {
  font-size: 16px;
  text-align: center;
  word-break: break-word;
  max-width: 100%;
  padding: 0 5px;
}

.kv-card .avatar-name {
  margin-top: 12px;
}

.copy-notification {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.avatar-card.copied .copy-notification {
  opacity: 1;
}

.rarity-5 .avatar-img {
  box-shadow: 0 0 10px 2px rgba(255, 215, 0, 0.5);
}

.rarity-4 .avatar-img {
  box-shadow: 0 0 10px 2px rgba(192, 192, 192, 0.5);
}

.avatar-card.active .halo {
  visibility: visible;
}

.halo {
  position: absolute;
  width: 68px;
  height: 68px;
  top: -4px;
  visibility: hidden;
  border-radius: 50%;
  z-index: 0;
  animation: rotateHalo-28e192c8 3s linear infinite;
}

@keyframes rotateHalo {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.halo::before {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border-radius: 50%;
  filter: brightness(0.5) contrast(0.5) invert(0.5);
  background: no-repeat center/contain url();
}

.kv-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
  max-width: 1200px;
  margin: 0 auto;
  align-items: center;
  justify-items: center;
}

.kv-card {
  position: relative;
}

.kv-pointer {
  position: absolute;
  visibility: hidden;
  top: 18px;
  left: -50px;
  width: 45px;
  height: 25px;
  background-size: cover;
  background-image: url();
}

.kv-card .avatar-img {
  position: relative;
  width: 180px;
  height: 60px;
  border-radius: 16px;
  overflow: visible;
}

.kv-card .avatar-img img {
  position: relative;
  z-index: 2;
  border-radius: 12px;
  box-shadow: 0 0 10px 2px rgba(192, 192, 192, 0.5);
}

.kv-card .avatar-img::after {
  visibility: hidden;
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border: #918b6b dotted;
  border-radius: 12px;
  overflow: auto;
}

.kv-card.active .avatar-img::after {
  visibility: visible;
  z-index: 1;
}

.kv-card.active .kv-pointer {
  visibility: visible;
}

/* 基础左右移动 */
.basic-move {
  animation: basicMove 0.5s infinite alternate;
}

@keyframes basicMove {
  to {
    transform: translateX(-10px);
  }
}

/* 往返移动 */
.round-trip {
  animation: roundTrip 0.5s infinite linear;
}

@keyframes roundTrip {
  0%, 100% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(-10px);
  }
}

/* 弹性移动 */
.bounce-move {
  animation: bounceMove 0.5s infinite alternate;
}

@keyframes bounceMove {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-10px);
  }
}

/* 悬停移动 */
.hover-move {
  transition: transform 0.5s;
}

.hover-move:hover {
  transform: translateX(-10px);
}

.avatar-card, .kv-card {
  cursor: pointer;
}
</style>